package coolq.yaozhenyong.controller;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.forte.qqrobot.anno.Filter;
import com.forte.qqrobot.anno.Listen;
import com.forte.qqrobot.anno.depend.Beans;
import com.forte.qqrobot.beans.messages.types.MsgGetTypes;
import com.forte.qqrobot.beans.types.KeywordMatchType;
import com.forte.qqrobot.component.forlemoc.beans.msgget.MsgPrivate;
import com.forte.qqrobot.sender.MsgSender;

import coolq.yaozhenyong.bean.BoobleansGroup;
import coolq.yaozhenyong.bean.QqPrivateMsgRecord;
import coolq.yaozhenyong.custom.QqAndHtml;
import coolq.yaozhenyong.custom.SpringContextUtil;
import coolq.yaozhenyong.service.BoobleansGroupService;
import coolq.yaozhenyong.service.QqPrivateMsgRecordService;
@Beans
@Listen(MsgGetTypes.privateMsg)
public class MyPrivateMsgRecordController {
	/****
	 * 监听
	 * @param msg
	 */
	@Filter
	public void saveprivateMsgrecprd(MsgPrivate msg) {
		BoobleansGroupService bean = SpringContextUtil.getBean(BoobleansGroupService.class);
		BoobleansGroup byId = bean.getById(2);
		if(byId.getBooleanok().equals("开启")) {
			QqPrivateMsgRecordService service = SpringContextUtil.getBean(QqPrivateMsgRecordService.class);
			QqPrivateMsgRecord record = new QqPrivateMsgRecord();
			record.setMsg(QqAndHtml.getMsghtml(msg.getMsg()));
			record.setQqnumber(msg.getQQ());
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			record.setTime(df.format(new Date()));
			record.setType(msg.getFont());
			service.save(record);
		}
	}
	
	@Filter(value = "取代码", keywordMatchType = KeywordMatchType.CONTAINS)
	public void qudaima(MsgPrivate msg,MsgSender msgsender) {
		//msg = msg.replace("[face-"+face[i]+"]", cqCodeUtil.getCQCode_face(face[i]));
		System.out.println(msg.getMsg());
		
		String[] split = msg.getMsg().split("\\[");
		if(split.length>1) {
			String obj = msg.getMsg().replaceAll("\\[", "(");
			obj = obj.replaceAll("\\]",")");
			obj = obj.replaceAll("取代码","");
			msgsender.SENDER.sendPrivateMsg(msg.getQQ(), obj);
		}else {
			msgsender.SENDER.sendPrivateMsg(msg.getQQ(), "您发的这个无法获取代码，可能是插件不支持！");
		}
	}
}
